﻿using System;
using System.IO;
using System.Windows.Markup;
using System.Collections.Generic;
using Petra.Gis;
using Petra.Gis.Geometry.Support;
using Petra.Gis.RenderingServices.GDIPlus;
using Petra.Gis.ReferenceSystemServices;
using Petra.Gis.DataServices.SHP;
using Petra.Gis.DataServices.GDO.Sqlserver;

namespace testGridMap
{
  public class testShpGeofond
  {

    public static void testMe()
    {


      BitmapMap map = new BitmapMap()
      {
        Width = 800,
        Height = 600,
        ProjectedCoordinateSystem = (ProjectedCoordinateSystem)Petra.Gis.Environment.SearchSrsBy("INGR", "49", "metre"),
        ProjectionExtent = new BoundingBox(-778000, -978000, -777000, -977000),
        NominalScale = 5000,
        ApplyMapRangeAsSpatialFilter = true,
        Scale = 150000
      };

      ShpConnection c = new ShpConnection()
      {
        ConnectionString =
        @"Data Source=C:\temp\GRDS_LCR\geofond ; 
         CoordinateSystemAuthority=INGR ;
         CoordinateSystemCode = 49 ;
         CoordinateStorageUnits = metre ;
         TextEncoding = 1252"
      };

      c.Open();

      // prepare command
      ShpSelectCommand cmd = new ShpSelectCommand();
      cmd.Connection = c;
      // this first to get smooth performance
      cmd.CommandType = System.Data.CommandType.TableDirect;
      // set valid command now command
      cmd.CommandText = "lonbpolcr";

      //prepare style
      Petra.Gis.RenderingServices.GDIPlus.Style stl = new Petra.Gis.RenderingServices.GDIPlus.Style()
      {
        Enabled = true,
        StyleScaleType = Petra.Gis.RenderingServices.PlanarBase.StyleScaleTypeEnum.ScaleIndependent
      };

      stl.StyleComponents.Add("Color", System.Drawing.Color.Black);
      stl.StyleComponents.Add("LineWidth", 2);
      stl.StyleComponents.Add("FillColor", System.Drawing.Color.FromArgb(128, 50, 255, 50));


      //SurfaceRenderer g = new SurfaceRenderer(map, stl);

      SurfaceRenderer g = new SurfaceRenderer()
      {
        Style = stl,
        SpatialFieldName = "Geometry" //optional, if user want to limit renderer to only one field
      };

      Petra.Gis.RenderingServices.PlanarBase.LegendNodeBase l = map.Legend.CreateLegendNode(cmd, g);

      map.Legend.ChildNodes.Add(l);

      System.Drawing.Bitmap b = map.Draw();

      b.Save("c:\\temp\\shp.png", System.Drawing.Imaging.ImageFormat.Png);
    }

  }
}
